package logic

import (
	"context"
	"fmt"

	"go-zero-demo-04/mall/result/api/internal/svc"
	"go-zero-demo-04/mall/result/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetAllLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetAllLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllLogic {
	return &GetAllLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetAllLogic) GetAll(req *types.GetAllRequest) (resp *types.GetGetAlListResponse, err error) {
	list, err := l.svcCtx.StudentModel.FindALL(l.ctx, req.CollegeName)
	if err != err {
		return nil, err
	}

	fmt.Println(list)

	var res []types.GetAllResponse

	for _, item := range list {
		var temp types.GetAllResponse
		temp.StudentName = item.StudentName
		temp.StudentID = item.StudentNo
		temp.CollegeName = item.CollegeName
		temp.DepartmentName = item.Departmentname
		temp.ClassID = item.ClassNo
		temp.Password = item.Password
		temp.Age = item.StudentAge
		temp.Sex = item.StudentSex
		res = append(res, temp)
	}
	return &types.GetGetAlListResponse{AllList: res}, nil
}
